import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()], //  自动导入 ElementPlus 组件
      imports: ["vue", "vue-router", "@vueuse/core", "pinia"],
      dirs: ["src/stores", "src/components", "src/hooks"],
    }),
    Components({
      // resolvers: [ElementPlusResolver()], //  自动导入 ElementPlus 组件    这里会导致index.scss中修改的UI组件的样式层级比原生低
      dirs: ["src/components"], // 组件所在目录
    }),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
      // 指定symbolId格式
      symbolId: "icon-[dir]-[name]",
      // 是否压缩
      svgoOptions: true,
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "@/styles/util.scss" as *; @use "@/styles/theme/element_plus.scss" as *;',
      },
    },
  },
  server: {
    host: "0.0.0.0",
    port: 3334,
    open: true,
    proxy: {
      "/api": {
        target: "http://172.16.6.222:8000",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, "/api"),
      },
      // 把key的路径代理到target位置
      "^/topo_image": {
        target: "https://172.17.0.246", // 代理到 目标路径
        changeOrigin: true,
        secure: false,
      },
      "^/simulation/": {
        // target: 'http://172.19.7.40:12001/', // 张亚超
        target: "https://172.25.7.210/api/", // 演示环境
        // target: 'http://172.19.5.197:12001', // 许超
        // target: 'http://172.17.0.181:12001', // 恒哥
        // target: 'http://172.19.6.166:12001', // 浩磊
        changeOrigin: true,
        secure: false,
      },
    },
    client: {
      overlay: false,
    },
  },
});
